package com.person.yan.takeout2017.net;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.person.yan.takeout2017.bean.ResponseInfo;

import java.io.IOException;

import okhttp3.Request;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by ywy on 2017/9/28.
 */

public abstract class InfoConvertDataUtils<T extends ResponseInfo> implements Callback<T> {

    @Override
    public void onResponse(Call<T> call, Response<T> response) {
        T body = response.body();
        String json = body.getData();
        if(!TextUtils.isEmpty(json)){
            showData(json);
        }else{
            showError(new RuntimeException("清空数据为空"));
        }
    }

    @Override
    public void onFailure(Call<T> call, Throwable t) {
        showError(t);

    }


    public abstract void showError(Throwable e);

    public abstract void showData(String json);

}
